﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication2.Model
{
    class Konsumen
    {
        
        int id;
        string nama;
        string alamat;
        string no_telp;
        string no_ktp;
        bool is_male;
        DateTime tgl_lahir;
        int umur;

        public Konsumen()
        {
            
        }

        public Konsumen(string _Nama)
        {
            Database db = new Database();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM konsumen WHERE nama = '" + _Nama + "'";

            db.Open();
            ds = db.ExecuteQuery(sql);
            dt = ds.Tables[0];
            DataRow dr = dt.Rows[0];

            id = (int)dr[0];
            nama = (string)dr[1];
            alamat = (string)dr[2];
            no_telp = (string)dr[3];
            no_ktp = (string)dr[4];
            is_male = (bool)dr[5];
            tgl_lahir = (DateTime)dr[6];
            umur = (int)dr[7];
            
            db.Close();
        }

        public static DataTable DaftarKonsumen()
        {
            Database db = new Database();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM konsumen";

            db.Open();
            ds = db.ExecuteQuery(sql);
            dt = ds.Tables[0];
            db.Close();

            return dt;
        }

        public static long AddKonsumen(string _nama, string _nomor, string _no_telp, string _alamat, string _is_male, string _tgl_lahir, string _umur)
        {
            Database db = new Database();
            long l;
            string sql = "INSERT INTO konsumen(nama, nomor, no_telp, alamat, is_male, tgl_lahir, umur) VALUES ('" + _nama + "','" + _nomor +
                    "','" + _no_telp + "','" + _alamat + "'," + _is_male + ",'" + _tgl_lahir + "'," + _umur + ");select currval('\"konsumen_id_seq\"')";

            db.Open();
            l = db.ExecuteNonQuery(sql);
            db.Close();

            return l;
        }

        public void UpdateKaryawan()
        {
        }

        public void DeleteKaryawan()
        {
        }

    }
}
